package com.ry.model.entity;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author ry
 * @since 2021-11-09 20:37
 **/
@Component
@Data
public class WechatProperties {
    @Value("${wechat.oauthUrl}")
    private String oauthUrl;
    @Value("${wechat.appId}")
    private String appId;
    @Value("${wechat.secret}")
    private String secret;
    @Value("${wechat.grantType}")
    private String grantType;

    public String getCode2SessionUrl(String code){
        //https://api.weixin.qq.com/sns/jscode2session?appid=wxe104b3bc974c82da&secret=40b109f2f5dd01303d2d8878cd0c4d26&js_code="+code+"&grant_type=authorization_code
        StringBuilder url = new StringBuilder(oauthUrl);
        url.append("?appid=");
        url.append(appId);
        url.append("&secret=");
        url.append(secret);
        url.append("&js_code=");
        url.append(code);
        url.append(grantType);

        return url.toString();
    }
}
